<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>设置我的密码</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/adminui/dist/css/admin.css}" media="all">
  <link rel="stylesheet" th:href="@{/style/custom.css}" media="all">
</head>
<body>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header">修改密码</div>
        <div class="layui-card-body" pad15>

          <form class="layui-form" lay-filter="LAY-setpass-front-form" id="LAY-setpass-front-form" action="" style="padding: 20px;">
            <input type="hidden" id="id" name="id" th:value="${user.id}"/>
            <input type="hidden" id="userId" name="userId" th:value="${user.userId}"/>
            <div class="layui-form-item">
              <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                <label class="layui-form-label">当前密码</label>
                <div class="layui-input-block">
                  <input type="password" name="oldPassword" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                  <input type="password" name="newPassword" lay-verify="pass" placeholder="请输入" id="LAY_password" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                <label class="layui-form-label">确认新密码</label>
                <div class="layui-input-block">
                  <input type="password" name="rePassword" lay-verify="repass" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
                <div class="layui-input-block" style="text-align:center;">
                  <input type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="LAY-setpass-front-submit" id="LAY-setpass-front-submit" value="提交">
                  <input type="reset" class="layui-btn layui-btn-primary" lay-filter="LAY-setpass-front-reset" id="LAY-setpass-front-reset" value="重置">
                </div>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>

<script th:src="@{/layui/layui.js}"></script>
<script>
  layui.config({
    base: '/'
  }).use(['index', 'set'], function () {
    let form = layui.form;

    //提交
    form.on('submit(LAY-setpass-front-submit)', function (data) {
      let field = data.field;
      delete field.rePassword;

      layui.admin.req({
        url: '/user/setpass',
        type: 'post',
        contentType: 'application/json;charset=utf-8',
        dataType: 'json',
        data: JSON.stringify(field),
        done: function (res) {
          //执行成功
          let index = parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
          layer.msg(res.msg, {icon: 1, time: 500}, function () {
            parent.layer.close(index);//关闭弹出层
            parent.layui.admin.events.closeThisTabs();
          });
        }
      });
    });

  });
</script>
</body>
</html>